package org.n.shop.controller;

import lombok.AllArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.n.shop.annotation.RequiresLogin;
import org.n.shop.result.RestResult;
import org.n.shop.service.OrderDetailService;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order/detail")
@AllArgsConstructor
public class OrderDetailController {
    private OrderDetailService orderDetailService;

    @RequiresLogin
    @RequestMapping("/last")
    public RestResult last(@RequestHeader("authorization") String authorization) {
        return orderDetailService.last(authorization);
    }

    @RequiresLogin
    @RequestMapping("/all")
    public RestResult all(@RequestHeader("authorization") String authorization,
                                     @RequestParam("timeType") int timeType,
                                     @RequestParam("page") int page,
                                     @RequestParam("pageSize") int pageSize,
                                     @RequestParam("logisticsState") int logisticsState,
                                     @RequestParam(value = "key", required = false) String key) {
        return orderDetailService.all(authorization, timeType, page, pageSize, logisticsState, key);
    }

    @RequiresLogin
    @RequestMapping("/id")
    public RestResult id(@RequestParam("id") int id) {
        return orderDetailService.id(id);
    }

    @RequiresLogin
    @RequestMapping("/del")
    public RestResult del(@RequestParam("id") int id) {
        return orderDetailService.del(id);
    }
}
